home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / pibt40s3.arc / PIBGOSSI.MOD < prev    next >
Text File  |  1987-09-30  |  14KB  |  367 lines

  1. (*--------------------------------------------------------------------------*)
  2. (*        Emulate_Gossip --- Gossip Mode from PibTerm to PibTerm            *)
  3. (*--------------------------------------------------------------------------*)
  4.  
  5. PROCEDURE Emulate_Gossip;
  6.  
  7. (*--------------------------------------------------------------------------*)
  8. (*                                                                          *)
  9. (*     Procedure:  Emulate_Gossip                                           *)
  10. (*                                                                          *)
  11. (*     Purpose:    Provides split-screen gossip mode, dumb terminal         *)
  12. (*                 emulation.                                               *)
  13. (*                                                                          *)
  14. (*     Calling sequence:                                                    *)
  15. (*                                                                          *)
  16. (*        Emulate_Gossip;                                                   *)
  17. (*                                                                          *)
  18. (*     Calls:                                                               *)
  19. (*                                                                          *)
  20. (*        Async_Receive                                                     *)
  21. (*        Process_Command                                                   *)
  22. (*        KeyPressed                                                        *)
  23. (*        Async_Send                                                        *)
  24. (*        Display_Character                                                 *)
  25. (*                                                                          *)
  26. (*     Called by:                                                           *)
  27. (*                                                                          *)
  28. (*        PibTerm (Main)                                                    *)
  29. (*                                                                          *)
  30. (*--------------------------------------------------------------------------*)
  31.  
  32. VAR
  33.    MyX                  : INTEGER;
  34.    MyY                  : INTEGER;
  35.    YourX                : INTEGER;
  36.    YourY                : INTEGER;
  37.    Save_Local           : BOOLEAN;
  38.    Save_AutoWrap        : BOOLEAN;
  39.    I                    : INTEGER;
  40.    Comm_Ch              : CHAR;
  41.    Done                 : BOOLEAN;
  42.    My_Last_Column_Hit   : BOOLEAN;
  43.    Your_Last_Column_Hit : BOOLEAN;
  44.    G_Window_Size        : INTEGER;
  45.    Divider_Line         : INTEGER;
  46.    Top_Of_Bottom        : INTEGER;
  47.    Input_Line           : AnyStr;
  48.    Save_Ansi_Last_Line  : INTEGER;
  49.  
  50. (*--------------------------------------------------------------------------*)
  51. (*       Display_Status_Message --- Display message for line mode           *)
  52. (*--------------------------------------------------------------------------*)
  53.  
  54. PROCEDURE Display_Status_Message( Status_Text : AnyStr );
  55.  
  56. VAR
  57.    Save_My_X: INTEGER;
  58.    Save_My_Y: INTEGER;
  59.  
  60. BEGIN (* Display_Status_Message *)
  61.  
  62.    Save_My_X := MyX;
  63.    Save_My_Y := MyY;
  64.  
  65.    WriteSXY( Status_Text, 55, Divider_Line, Global_Text_Attribute );
  66.  
  67.    MyX := Save_My_X;
  68.    MyY := Save_My_Y;
  69.  
  70. END   (* Display_Status_Message *);
  71.  
  72. (*--------------------------------------------------------------------------*)
  73. (*  Do_Gossip_Line_Mode --- Process keyboard input for gossip line mode     *)
  74. (*--------------------------------------------------------------------------*)
  75.  
  76. PROCEDURE Do_Gossip_Line_Mode;
  77.  
  78. VAR
  79.    Ch                    : CHAR;
  80.    Save_Gossip_Line_Mode : BOOLEAN;
  81.  
  82. BEGIN (* Do_Gossip_Line_Mode *)
  83.                                    (* Read in entire line *)
  84.    IF KeyPressed THEN
  85.       BEGIN
  86.  
  87.          Window( 1, Top_Of_Bottom, Max_Screen_Col, Ansi_Last_Line );
  88.          GoToXY( MyX, MyY );
  89.                                    (* Get first character *)
  90.          READ( Kbd, Comm_Ch );
  91.  
  92.          IF ( Comm_Ch = CHR( CR ) ) THEN
  93.             BEGIN
  94.                Display_Status_Message(' Sending line ====');
  95.                Async_Send_String( Input_Line );
  96.                Input_Line[0] := #0;
  97.                Display_Status_Message(' Line sent =======');
  98.             END
  99.          ELSE IF ( Comm_Ch = CHR( ESC ) ) THEN
  100.             BEGIN
  101.                Save_Gossip_Line_Mode := Gossip_Line_Mode;
  102.                Process_Command( Comm_Ch, FALSE, PibTerm_Command );
  103.                IF PibTerm_Command <> Null_Command THEN
  104.                   Execute_Command( PibTerm_Command, Done, FALSE );
  105.                IF ( Gossip_Line_Mode <> Save_Gossip_Line_Mode ) THEN
  106.                   IF Gossip_Line_Mode THEN
  107.                      Display_Status_Message(' Awaiting input ==' )
  108.                   ELSE
  109.                      Display_Status_Message('==================' );
  110.             END
  111.          ELSE
  112.             BEGIN
  113.                Display_Status_Message(' Reading keyboard ');
  114.                Input_Line := Comm_Ch;
  115.                Ch := Edit_String( Input_Line, 255, 1, 2, WhereY,
  116.                                   Max_Screen_Col, FALSE, 0 );
  117.                IF ( Ch <> CHR( ESC ) ) THEN
  118.                   BEGIN
  119.                      WRITELN;
  120.                      Input_Line := Input_Line + CHR( CR );
  121.                      Display_Status_Message(' Waiting to send =');
  122.                   END
  123.                ELSE
  124.                   BEGIN
  125.                      Input_Line[0] := #0;
  126.                      Display_Status_Message(' Input cancelled ==');
  127.                   END;
  128.             END;
  129.                                    (* Remember position! *)
  130.             MyX := WhereX;
  131.             MyY := WhereY;
  132.  
  133.          END;
  134.  
  135. END   (* Do_Gossip_Line_Mode *);
  136.  
  137. (*--------------------------------------------------------------------------*)
  138. (*  Do_Gossip_Character_Mode --- Process kbd input for gossip char. mode    *)
  139. (*--------------------------------------------------------------------------*)
  140.  
  141. PROCEDURE Do_Gossip_Character_Mode;
  142.  
  143. BEGIN (* Do_Gossip_Character_Mode *)
  144.  
  145.                                    (* Process local user's input      *)
  146.       IF KeyPressed THEN
  147.          BEGIN
  148.  
  149.             Window( 1, Top_Of_Bottom, Max_Screen_Col, Ansi_Last_Line );
  150.             GoToXY( MyX, MyY );
  151.  
  152.             READ( Kbd , Comm_Ch );
  153.  
  154.             CASE ORD( Comm_Ch ) OF
  155.  
  156.                ESC:  IF KeyPressed THEN
  157.                         BEGIN
  158.                            Process_Command( Comm_Ch, FALSE, PibTerm_Command );
  159.                            IF PibTerm_Command <> Null_Command THEN
  160.                               Execute_Command( PibTerm_Command, Done, FALSE );
  161.                         END
  162.                      ELSE
  163.                         BEGIN
  164.                            IF Local_Echo THEN Async_Stuff( Comm_Ch );
  165.                            Async_Send( Comm_Ch );
  166.                         END;
  167.  
  168.  
  169.                BS:   BEGIN
  170.                         Comm_Ch := BS_Char;
  171.                         IF Local_Echo THEN
  172.                            BEGIN
  173.                               Last_Column_Hit := My_Last_Column_Hit;
  174.                               Display_Character( Comm_Ch );
  175.                               IF Do_Script_Tests THEN
  176.                                  Do_Script_Checks( Comm_Ch );
  177.                               My_Last_Column_Hit := Last_Column_Hit;
  178.                            END;
  179.                         Async_Send( Comm_Ch );
  180.                      END;
  181.  
  182.                DEL:  BEGIN
  183.                         Comm_Ch := Ctrl_BS_Char;
  184.                         IF Local_Echo THEN
  185.                            BEGIN
  186.                               Last_Column_Hit := My_Last_Column_Hit;
  187.                               Display_Character( Comm_Ch );
  188.                               IF Do_Script_Tests THEN
  189.                                  Do_Script_Checks( Comm_Ch );
  190.                               My_Last_Column_Hit := Last_Column_Hit;
  191.                            END;
  192.                         Async_Send( Comm_Ch );
  193.                      END;
  194.  
  195.                CR:   BEGIN
  196.                         IF Local_Echo THEN
  197.                            BEGIN
  198.                               Last_Column_Hit := My_Last_Column_Hit;
  199.                               Display_Character( Comm_Ch );
  200.                               IF Do_Script_Tests THEN
  201.                                  Do_Script_Checks( Comm_Ch );
  202.                               Display_Character( CHR( LF ) );
  203.                               IF Do_Script_Tests THEN
  204.                                  Do_Script_Checks( Comm_Ch );
  205.                               My_Last_Column_Hit := Last_Column_Hit;
  206.                            END;
  207.                         Async_Send( Comm_Ch );
  208.                      END;
  209.  
  210.                ELSE
  211.                      BEGIN
  212.                         IF Local_Echo THEN
  213.                            BEGIN
  214.                               Last_Column_Hit := My_Last_Column_Hit;
  215.                               Display_Character( Comm_Ch );
  216.                               IF Do_Script_Tests THEN
  217.                                  Do_Script_Checks( Comm_Ch );
  218.                               My_Last_Column_Hit := Last_Column_Hit;
  219.                            END;
  220.                         Async_Send( Comm_Ch );
  221.                      END;
  222.  
  223.             END (* CASE ORD( Comm_Ch ) *);
  224.  
  225.                                    (* Remember position! *)
  226.             MyX := WhereX;
  227.             MyY := WhereY;
  228.  
  229.          END (* KeyPressed *);
  230.  
  231. END   (* Do_Gossip_Character_Mode *);
  232.  
  233. (*--------------------------------------------------------------------------*)
  234.  
  235. BEGIN (* Emulate_Gossip *)
  236.                                    (* Ensure we're in text mode *)
  237.  
  238.    Init_Text_Terminal;
  239.                                    (* Set status line *)
  240.  
  241.    Set_Status_Line_Name(Short_Terminal_Name);
  242.  
  243.                                    (* Status line to last line *)
  244.    IF Do_Status_Line THEN
  245.       BEGIN
  246.          Ansi_Last_Line := PRED( Max_Screen_Line );
  247.          Write_To_Status_Line( Status_Line_Name, 1 );
  248.       END
  249.    ELSE
  250.       Ansi_Last_Line := Max_Screen_Line;
  251.  
  252.                                    (* Turn on local echo, set initial *)
  253.                                    (* positions for each user's       *)
  254.                                    (* message area.                   *)
  255.    Save_Local     := Local_Echo;
  256.    Local_Echo     := TRUE;
  257.    MyX            := 1;
  258.    MyY            := 1;
  259.    YourX          := 1;
  260.    YourY          := 1;
  261.    Done           := FALSE;
  262.    Input_Line[0]  := #0;
  263.    G_Window_Size  := Gossip_Window_Size;
  264.  
  265.                                    (* Ensure proper wrapping *)
  266.    My_Last_Column_Hit   := FALSE;
  267.    Your_Last_Column_Hit := FALSE;
  268.    Save_AutoWrap        := Auto_Wrap_Mode;
  269.    Auto_Wrap_Mode       := TRUE;
  270.  
  271.                                    (* Split screen into two parts:    *)
  272.                                    (* Upper for local user, lower for *)
  273.                                    (* remote user.                    *)
  274.  
  275.    Window( 1, 1, Max_Screen_Col, Ansi_Last_Line );
  276.    Set_Screen_Size( Ansi_Last_Line , Max_Screen_Col );
  277.    Clear_Window;
  278.                                    (* Print divider                   *)
  279.  
  280.    Divider_Line  := SUCC( G_Window_Size );
  281.    Top_Of_Bottom := SUCC( Divider_Line  );
  282.  
  283.    GoToXY( 1 , Divider_Line );
  284.  
  285.    FOR I := 1 TO 34 DO WRITE('=');
  286.    WRITE('Gossip Mode');
  287.    FOR I := 1 TO 35 DO WRITE('=');
  288.  
  289.    IF Gossip_Line_Mode THEN
  290.       Display_Status_Message(' Awaiting input ==' );
  291.  
  292.    Do_Script_Tests := Waitstring_Mode OR When_Mode OR
  293.                       WaitCount_Mode  OR WaitQuiet_Mode OR
  294.                       Script_Learn_Mode;
  295.  
  296.    REPEAT
  297.                                    (* Process local user's input      *)
  298.       IF Gossip_Line_Mode THEN
  299.          Do_Gossip_Line_Mode
  300.       ELSE
  301.          Do_Gossip_Character_Mode;
  302.                                    (* Process script file entry *)
  303.  
  304.       IF ( Script_File_Mode AND ( NOT ( Done OR Really_Wait_String ) ) ) THEN
  305.          BEGIN
  306.             Get_Script_Command( PibTerm_Command );
  307.             Execute_Command   ( PibTerm_Command , Done , TRUE );
  308.          END;
  309.                                    (* Hold everything while scroll lock on *)
  310.  
  311.       IF Scroll_Lock_On THEN
  312.          Handle_Scroll_Lock;
  313.                                    (* Process remote user's input *)
  314.  
  315.       IF Async_Receive( Comm_Ch ) THEN
  316.  
  317.          BEGIN  (* Comm_Ch found *)
  318.  
  319.             Save_Ansi_Last_Line := Ansi_Last_Line;
  320.             Ansi_Last_Line      := G_Window_Size;
  321.  
  322.             Window( 1, 1, Max_Screen_Col, G_Window_Size );
  323.             GoToXY( YourX, YourY );
  324.  
  325.             Last_Column_Hit := Your_Last_Column_Hit;
  326.             Comm_Ch         := TrTab[ Comm_Ch ];
  327.             Display_Character( Comm_Ch );
  328.             IF Do_Script_Tests THEN
  329.                Do_Script_Checks( Comm_Ch );
  330.             Your_Last_Column_Hit := Last_Column_Hit;
  331.             Ansi_Last_Line       := Save_Ansi_Last_Line;
  332.  
  333.             YourX := WhereX;
  334.             YourY := WhereY;
  335.  
  336.          END (* Comm_Ch found *)
  337.                                    (* Check if waitstring time exhausted *)
  338.       ELSE
  339.          BEGIN
  340.             Async_Line_Status := Async_Line_Status AND $FD;
  341.             IF Really_Wait_String THEN
  342.                Check_Wait_String_Time;
  343.             IF ( NOT KeyPressed ) THEN
  344.                GiveAwayTime( 1 );
  345.          END;
  346.                                     (* Send saved line if at left margin *)
  347.       IF ( YourX = 1 ) THEN
  348.          IF ( ORD( Input_Line[0] ) > 0 ) THEN
  349.             BEGIN
  350.                Display_Status_Message(' Sending line ====');
  351.                Async_Send_String( Input_Line );
  352.                Input_Line[0] := #0;
  353.                Display_Status_Message(' Line sent =======' );
  354.             END;
  355.  
  356.    UNTIL ( NOT Gossip_Mode_On ) OR Done;
  357.  
  358.                                   (* Restore single screen mode *)
  359.  
  360.    Local_Echo          := Save_Local;
  361.    Auto_Wrap_Mode      := Save_AutoWrap;
  362.  
  363.    Window( 1, 1, Max_Screen_Col, Ansi_Last_Line );
  364.    Clear_Window;
  365.  
  366. END    (* Emulate_Gossip *);
  367.